// 线上引用 cdn
// 是否为生产模式
const isProd = process.env.NODE_ENV.startsWith('prod')
const externals = {
  'vue': 'Vue',
  'vue-router': 'VueRouter',
  'axios': 'axios',
  'nprogress': 'NProgress',
  'element-ui': 'ELEMENT',
  'js-cookie': 'Cookies',
  'dayjs': 'dayjs'
}
// cdn 资源
const cdn = {
  css: [
    'https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.3/theme-chalk/index.min.css',
    'https://cdn.staticfile.org/nprogress/0.2.0/nprogress.min.css'
  ],
  js: [
    'https://cdn.bootcdn.net/ajax/libs/vue/2.6.11/vue.min.js',
    'https://cdn.bootcdn.net/ajax/libs/vue-router/3.2.0/vue-router.min.js',
    'https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js',
    'https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.3/index.min.js',
    'https://cdn.staticfile.org/nprogress/0.2.0/nprogress.min.js',
    'https://cdn.bootcdn.net/ajax/libs/js-cookie/2.2.0/js.cookie.min.js',
    'https://cdn.bootcdn.net/ajax/libs/dayjs/1.10.6/dayjs.min.js'
  ]
}
module.exports = {
  lintOnSave: false,
  publicPath: '/exp_schedule/',
  chainWebpack: config => {
    // 生产环境
    config.when(isProd, config => {
      // 改变入口
      config.entry('app').clear().add('./src/main-prod.js')
      config.set('externals', externals)
      config.plugin('html').tap(args => {
        args[0].cdn = cdn
        args[0].isProd = isProd
        return args
      })
    })
    // 开发环境
    config.when(!isProd, config => {
      // 改变入口
      config.entry('app').clear().add('./src/main-dev.js')
      config.plugin('html').tap(args => {
        args[0].isProd = isProd
        return args
      })
    })
  }
}
